home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 37 / CD Expert nº 37.iso / LastCall / lastcall.exe / stuff / lastcall.dxr / 00159.ls < prev    next >
Encoding:
Text File  |  2000-03-27  |  8.3 KB  |  290 lines

  1. global gTable, debug
  2.  
  3. on closeDB
  4.   global gDB
  5.   if objectp(gDB) then
  6.     gDB = 0
  7.   end if
  8. end
  9.  
  10. on initDB fileName, tableName
  11.   global gDB
  12.   gDB = new(xtra("V12dbe"), basePath() & fileName, "ReadOnly", EMPTY)
  13.   gTable = new(xtra("V12table"), mGetRef(gDB), tableName)
  14. end
  15.  
  16. on countDB
  17.   mGoFirst(gTable)
  18.   numRecs = mSelectCount(gTable)
  19.   mGoFirst(gTable)
  20.   put "Found" && numRecs && "records in the glassware database"
  21. end
  22.  
  23. on initRecipes
  24.   global gRecipes, gOldRecipes, gIngredients, gSecretRecipeBook
  25.   if gOldRecipes then
  26.     if FileExists(gSecretRecipeBook) and not authoring() then
  27.       gRecipes = value(retrieveFile(gSecretRecipeBook))
  28.     else
  29.       gRecipes = getOldRecipesDB()
  30.     end if
  31.     exit
  32.   end if
  33.   gRecipes = [:]
  34.   if 0 then
  35.     initDB("recipes.v12", "recipes")
  36.     mOrderBy(gTable, "drinkName")
  37.     mSelectAll(gTable)
  38.     gRecipes = mGetSelection(gTable, "PropertyList")
  39.     closeDB()
  40.   else
  41.     initDB("recipes.v12", "recipes")
  42.     mOrderBy(gTable, "recID")
  43.     mSelectAll(gTable)
  44.     ingredients = mGetSelection(gTable, "PropertyList")
  45.     closeDB()
  46.     initDB("recipes.v12", "recipeName")
  47.     mOrderBy(gTable, "drinkName")
  48.     mSelectAll(gTable)
  49.     gRecipes = mGetSelection(gTable, "PropertyList")
  50.     closeDB()
  51.   end if
  52.   repeat with thisDrink in gRecipes
  53.     thisDrink[#RECID] = integer(thisDrink[#RECID])
  54.     thisDrink[#DIFFICULTY] = integer(thisDrink[#DIFFICULTY])
  55.     ingList = []
  56.     specialCase = []
  57.     repeat with X = 1 to count(ingredients)
  58.       nextIng = ingredients[X]
  59.       if nextIng[#RECID] = thisDrink[#RECID] then
  60.         INGID = integer(nextIng[#INGID])
  61.         add(ingList, [#INGID: INGID, #ingName: findingredientbyid(INGID), #q: nextIng[#q], #p: nextIng[#p], #o: nextIng[#order]])
  62.         repeat with Y = 1 to count(gIngredients)
  63.           thisIng = gIngredients[Y]
  64.           refname = getPropAt(gIngredients, Y)
  65.           if thisIng[#INGID] = INGID then
  66.             if thisIng[#Xbottle] then
  67.               add(specialCase, 1)
  68.             else
  69.               if thisIng[#CATID] = 5 then
  70.                 add(specialCase, 2)
  71.               else
  72.                 case refname of
  73.                   #lemontwist, #limetwist:
  74.                     add(specialCase, 3)
  75.                   #coatandrim:
  76.                     add(specialCase, 4)
  77.                   #Muddle:
  78.                     add(specialCase, 5)
  79.                 end case
  80.               end if
  81.             end if
  82.             exit repeat
  83.           end if
  84.         end repeat
  85.       end if
  86.     end repeat
  87.     if count(specialCase) then
  88.       thisDrink[#SPECIAL_CASE] = duplicate(specialCase)
  89.     end if
  90.     thisDrink[#ingredients] = bubbleSort(duplicate(ingList))
  91.   end repeat
  92. end
  93.  
  94. on bubbleSort ingList
  95.   repeat with X = count(ingList) down to 2
  96.     repeat with Y = X - 1 down to 1
  97.       if ingList[Y][#o] > ingList[X][#o] then
  98.         temp1 = duplicate(ingList[X])
  99.         temp2 = duplicate(ingList[Y])
  100.         ingList[X] = temp2
  101.         ingList[Y] = temp1
  102.       end if
  103.     end repeat
  104.   end repeat
  105.   return ingList
  106. end
  107.  
  108. on initIngredients
  109.   global gIngredients, gOldIngredients, gSecretIngredients
  110.   gIngredients = [:]
  111.   if gOldIngredients then
  112.     if FileExists(gSecretIngredients) and not authoring() then
  113.       gIngredients = value(retrieveFile(gSecretIngredients))
  114.     else
  115.       gIngredients = getOldIngredientsDB()
  116.     end if
  117.     sort(gIngredients)
  118.   else
  119.     gIngredients = [:]
  120.     initDB("recipes.v12", "ingredients")
  121.     mOrderBy(gTable, "ingID")
  122.     mSelectAll(gTable)
  123.     temp = mGetSelection(gTable, "PropertyList")
  124.     repeat with X = 1 to count(temp)
  125.       thisIng = symbol(temp[X][#refname])
  126.       addProp(gIngredients, thisIng, temp[X])
  127.       deleteProp(gIngredients[thisIng], #refname)
  128.       oldLaser = getLaser(thisIng)
  129.       if (oldLaser = "void") or (oldLaser = "<void>") or (oldLaser = EMPTY) then
  130.         gIngredients[thisIng][#laserPoint] = VOID
  131.       else
  132.         if oldLaser starts "ppint" then
  133.           nothing()
  134.         else
  135.           gIngredients[thisIng][#laserPoint] = value("point" & oldLaser)
  136.         end if
  137.       end if
  138.       oldColor = getLiquidColor(thisIng)
  139.       if (oldColor = "void") or (oldColor = "<void>") or (oldColor = EMPTY) then
  140.         gIngredients[thisIng][#color] = VOID
  141.       else
  142.         gIngredients[thisIng][#color] = value("rgb" & oldColor)
  143.       end if
  144.       gIngredients[thisIng][#CATID] = integer(gIngredients[thisIng][#CATID])
  145.       deleteProp(gIngredients[thisIng], #QUANTITY_FIELDNAME)
  146.       deleteProp(gIngredients[thisIng], #POINTS_FIELDNAME)
  147.       gIngredients[thisIng][#Xbottle] = integer(gIngredients[thisIng][#Xbottle])
  148.       altList = []
  149.       alt = value("list" & gIngredients[thisIng][#ALTERNATEING])
  150.       if not voidp(alt) then
  151.         repeat with z = 1 to count(alt) / 2
  152.           first = (z * 2) - 1
  153.           second = z * 2
  154.           add(altList, [#ingA: alt[first], #pA: alt[second]])
  155.         end repeat
  156.       end if
  157.       if count(altList) then
  158.         gIngredients[thisIng][#alt] = altList
  159.       end if
  160.       deleteProp(gIngredients[thisIng], #ALTERNATEING)
  161.     end repeat
  162.     closeDB()
  163.   end if
  164. end
  165.  
  166. on correctUserTips
  167.   global gUserTips
  168.   repeat with X = 1 to count(gUserTips)
  169.     gUserTips[X][#tipText] = replaceAltOption(gUserTips[X][#tipText])
  170.   end repeat
  171. end
  172.  
  173. on initUserTips
  174.   global gUserTips, gOldUserTips
  175.   if gOldUserTips then
  176.     gUserTips = getOldUserTipsDB()
  177.   else
  178.     gUserTips = [:]
  179.     initDB("recipes.v12", "Tip_Table")
  180.     mOrderBy(gTable, "ID")
  181.     mSelectAll(gTable)
  182.     temp = mGetSelection(gTable, "PropertyList")
  183.     repeat with X = 1 to count(temp)
  184.       thisTip = temp[X]
  185.       tipName = thisTip[#TIP_NAME]
  186.       tipSymbol = symbol(tipName)
  187.       addProp(gUserTips, tipSymbol, [#tipCode: tipSymbol, #tipName: tipName, #tipText: thisTip[#tip], #tipType: symbol(thisTip[#TIP_CAT])])
  188.     end repeat
  189.     closeDB()
  190.   end if
  191. end
  192.  
  193. on cleanUpRecipes
  194.   global gRecipes, gOldRecipes
  195.   oldPrecision = the floatPrecision
  196.   set the floatPrecision to 2
  197.   if not gOldRecipes then
  198.     if not voidp(gRecipes) then
  199.       member("recipeDB").scriptText = "on getOldRecipesDB" & RETURN & "return" && gRecipes & RETURN & "end"
  200.     end if
  201.     gOldRecipes = 1
  202.   end if
  203.   set the floatPrecision to oldPrecision
  204. end
  205.  
  206. on cleanupIngredients
  207.   global gIngredients, gOldIngredients
  208.   if not gOldIngredients then
  209.     oldPrec = the floatPrecision
  210.     set the floatPrecision to 3
  211.     if not voidp(gIngredients) then
  212.       member("ingredientDB").scriptText = "on getOldIngredientsDB" & RETURN & "return" && gIngredients & RETURN & "end"
  213.     end if
  214.     gOldIngredients = 1
  215.     set the floatPrecision to oldPrec
  216.   end if
  217. end
  218.  
  219. on cleanupUserTips
  220.   global gUserTips, gOldUserTips
  221.   if not gOldUserTips then
  222.     if not voidp(gUserTips) then
  223.       member("userTipsDB").scriptText = "on getOldUserTipsDB" & RETURN & "return" && gUserTips & RETURN & "end"
  224.     end if
  225.     gOldUserTips = 1
  226.   end if
  227. end
  228.  
  229. on cleanupCharActions
  230.   global gCharacterActions, gOldCharActions
  231.   if not gOldCharActions then
  232.     if not voidp(gCharacterActions) then
  233.       member("charactionsDB").scriptText = "on getOldCharActionsDB" & RETURN & "return" && gCharacterActions & RETURN & "end"
  234.     end if
  235.     gOldCharActions = 1
  236.   end if
  237. end
  238.  
  239. on cleanupGlassware
  240.   global gGlassware, gOldGlassware
  241.   if not gOldGlassware then
  242.     if not voidp(gGlassware) then
  243.       member("glasswareDB").scriptText = "on getOldGlasswareDB" & RETURN & "return" && gGlassware & RETURN & "end"
  244.     end if
  245.     gOldGlassware = 1
  246.   end if
  247. end
  248.  
  249. on cleanupGameLevels
  250.   global gGameSetup, gOldGameLevels
  251.   if not gOldGameLevels then
  252.     if not voidp(gGameSetup) then
  253.       member("gameLevelsDB").scriptText = "on getOldGameLevelsDB" & RETURN & "return" && gGameSetup & RETURN & "end"
  254.     end if
  255.     gOldGameLevels = 1
  256.   end if
  257. end
  258.  
  259. on cleanupFlashRects
  260.   global gFlashRects, gOldFlashRects
  261.   if not gOldFlashRects then
  262.     set the floatPrecision to 0
  263.     if not voidp(gFlashRects) then
  264.       member("flashRectsDB").scriptText = "on getOldFlashRectsDB" & RETURN & "return" && gFlashRects & RETURN & "end"
  265.     end if
  266.     gOldFlashRects = 1
  267.     set the floatPrecision to 2
  268.   end if
  269. end
  270.  
  271. on cleanupcharInfo
  272.   global gOldCharInfo, gImplementedCharacters
  273.   if not gOldCharInfo then
  274.     if not voidp(gImplementedCharacters) then
  275.       member("charInfoDB").scriptText = "on getOldCharInfoDB" & RETURN & "return" && gImplementedCharacters & RETURN & "end"
  276.     end if
  277.     gOldCharInfo = 1
  278.   end if
  279. end
  280.  
  281. on cleanup
  282.   cleanUpRecipes()
  283.   cleanupIngredients()
  284.   cleanupCharActions()
  285.   cleanupGlassware()
  286.   cleanupFlashRects()
  287.   cleanupcharInfo()
  288.   closeDB()
  289. end
  290.